/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package RunnableOldClass;
//import RunableSt.SetNews;
import RunableSt.authenticator;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.*;
import java.io.*;
import java.util.Vector;
import java.util.Calendar;
import java.util.Properties;
import javax.swing.Timer;
/**
 *
 * @author ifcouse
 */
public class GETSTOCK implements Runnable  {

   
   
   int count=1;int count1=0;
    @Override
    public void run() {
       // javax.swing.Timer WorkControl = new javax.swing.Timer(500, new SetNews());  
      //  WorkControl.start();
     
       for(;;){ 
           count=1;
          StringBuffer content = new StringBuffer("");
           ++count1;
             GETThread.jLabel10.setText(String.valueOf(count1));
         try {
           // URL sUrl = new URL("http://www.settrade.com/C13_MarketSummaryStockType.jsp?type=S");
              String sUrl = "http://www.settrade.com/C13_MarketSummary.jsp?detail=INDUSTRY&sector=AGRI",
               proxy = "proxy.up.ac.th",
               port = "8080",
               username = "up\\51286885",
               password = "7489250721";

       //     System.out.println("sURL " + sUrl);

         String buffer;
           URL server = new URL(sUrl);
        // URLConnection conn = sUrl.openConnection();
          Authenticator.setDefault(new authenticator(
                        username,password));
         Properties systemProperties = System.getProperties();
           systemProperties.setProperty("http.proxyHost",proxy);
           systemProperties.setProperty("http.proxyPort",port);
            HttpURLConnection connection = (HttpURLConnection)server.openConnection();
           connection.connect();
          BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(),"TIS-620")) ;
          
         while((buffer = in.readLine()) != null) {
                 count++;
                content.append(count+"-->"+buffer+"\n");
                
           }
           in.close();
          // System.out.println("========================");
         //  System.out.println(content.toString() + "\n"); 
            PrintStream out = new PrintStream(new FileOutputStream("StockFile.txt"));
            out.println(content.toString());
            out.close();
        //   System.out.println("========================");
        } catch (Exception e){
            System.err.println("Couldn't create help URL: " + e);
        }
        
           try {
               
           //  ReadRank.SetDb();
            Thread.sleep(5000);
        } catch (InterruptedException ex) {
        }
       }

    }
    
}
class SetStock implements ActionListener{
int count=1;
    @Override
    public void actionPerformed(ActionEvent ae) {
     //  System.out.println("--");
               
        if(count==1){
           GETThread.jLabel12.setText("Working."); 
           count++;
        }else if(count==2){
            GETThread.jLabel12.setText("Working.."); 
             count++;
        }else if(count==3){
            GETThread.jLabel12.setText("Working..."); 
            count=1;
        }
      
    }}